package com.gla.giliair.web.admin;

import com.gla.giliair.util.MapGenerator;
import com.gla.giliair.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description:
 * @Author: Yingtian qian
 * @Date: 2021/8/25 20:41
 */
@Api(tags = "静态座位管理模块")
@RestController
@RequestMapping("/api/adminX")
public class AdminStaticSeatController extends BaseController {
    @ApiOperation(value = "获取全部静态座位列表", notes = "获取全部静态座位列表，有多种排序方式", produces = "application/json")
    @GetMapping("/findAllStaticSeat")
    @ResponseBody
    public Map<String, Object> findAllStaticSeat(//排序关键词：staticSeatId、seatNumber、seatType、planemodelId
                                                 // createTime、updateTime
                                                 //不填关键词默认按id逆向排序
                                                 @RequestParam(value = "sort", defaultValue = "planemodelId") String sort,
                                                 //正反序只对关键词生效
                                                 @RequestParam(value = "isASC", defaultValue = "false") boolean isASC,
                                                 @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                 @RequestParam(value = "pageSize", defaultValue = "300") Integer pageSize) {
        return staticSeatService.findAllStaticSeats(sort, isASC, page, pageSize);
    }

    @ApiOperation(value = "获取静态座位列表", notes = "根据飞机型号，获取静态座位列表", produces = "application/json")
    @GetMapping("/staticSeatList")
    @ResponseBody
    public Map<String, Object> findStaticSeat(@RequestParam("planemodelId") Long planemodelId,
                                              @RequestParam(value = "page", defaultValue = "1") Integer page,
                                              @RequestParam(value = "pageSize", defaultValue = "300") Integer pageSize) {
        return staticSeatService.findStaticSeatsByPlanemodelId(planemodelId, page, pageSize);
    }

    @ApiOperation(value = "批量添加静态座位", notes = "批量添加静态座位", produces = "application/json")
    @PostMapping("/addStaticSeats")
    @ResponseBody
    public Map<String, Object> addStaticSeats(@RequestParam("planemodelId") Long planemodelId,
                                             //座位类型：0、1、2
                                             @RequestParam("seatType") Integer seatType,
                                             //每行每区座位数：如2-2座位，3-3座位，2-4-2座位；最少两个区，最多三个区，合计每行不能超过12位
                                             @RequestParam("numPerRow") Integer[] numPerRow,
                                             //插入的行数
                                             @RequestParam("rowNum") Integer rowNum) {
        if (seatType != 0 && seatType != 1 && seatType != 2) {
            return MapGenerator.getRes(500, "座位类型不存在！");
        }
        return staticSeatService.addStaticSeats(planemodelId, seatType, numPerRow, rowNum);
    }

    @ApiOperation(value = "删除静态座位", notes = "删除单个静态座位", produces = "application/json")
    @PostMapping("/deleteStaticSeat")
    @ResponseBody
    public Map<String, Object> deleteStaticSeat(@RequestParam("staticSeatId") Long staticSeatId) {
        if (staticSeatId == null) {
            return MapGenerator.getRes(500, "请输入静态座位id！");
        }
        return staticSeatService.deleteStaticSeat(staticSeatId);
    }
}
